1620B - Triangles on a Rectangle - CodeForces Solution


geometry greedy math *1000

Please click on ads to support us..

Python Code:

R=lambda:map(int,input().split())
t,=R()
while t:
 t-=1;w,h=R();r=0
 for x in[h,h,w,w]:k,m,*_,M=R();r=max(r,x*(M-m))
 print(r)
	   	    						 	  	 	  			 		

C++ Code:

#define ll long long
#define ull unsigned long long
#define cy cout << "YES" << endl
#define cn cout << "NO" << endl
#define pb push_back
#define ff first
#define ss second
#include <bits/stdc++.h>
 
// #include <boost/multiprecision/cpp_ll.hpp>
using namespace std;
/*bool ip(ull n){ //prime check
    bool f = 1;
    if(n==1 || n==0){
        f = 1;
    }
    else{
    for(ull i = 2;i*i<n;i++){
        if(n%i==0){
            f = 0;
            break;
        }
    }
    }
    return f;
}*/
void solve(){
    ll w,h;
    cin >> w >> h;
    ll ans = 0;
    vector<ll> s1,s2,s3,s4;
    int n1,n2,n3,n4;
    cin >> n1;
    for(int i =0;i<n1;i++){
        ll a;
        cin >> a;
        s1.pb(a);
    }
    cin >> n2;
    for(int i =0;i<n2;i++){
        ll a;
        cin >> a;
        s2.pb(a);
    }
    cin >> n3;
    for(int i =0;i<n3;i++){
        ll a;
        cin >> a;
        s3.pb(a);
    }
    cin >> n4;
    for(int i =0;i<n4;i++){
        ll a;
        cin >> a;
        s4.pb(a);
    }
    ll s1d,s2d,s3d,s4d;
    s1d = *max_element(s1.begin(),s1.end()) - *min_element(s1.begin(),s1.end());
    s2d = *max_element(s2.begin(),s2.end()) - *min_element(s2.begin(),s2.end());
    s3d = *max_element(s3.begin(),s3.end()) - *min_element(s3.begin(),s3.end());
    s4d = *max_element(s4.begin(),s4.end()) - *min_element(s4.begin(),s4.end());

    ans = max(max(s1d,s2d)*h,max(s3d,s4d)*w);
    cout << ans << endl;

}

 
int main ()
{
  ios::sync_with_stdio (0);
  cin.tie (0);
  cout.tie (0);
  ll t = 1;
  cin >> t;
  while (t--)
    {
      solve ();
    }
  return 0;
}


Comments

Submit
0 Comments
More Questions

1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves
230B - T-primes
630A - Again Twenty Five
1234D - Distinct Characters Queries
1183A - Nearest Interesting Number
1009E - Intercity Travelling
1637B - MEX and Array
224A - Parallelepiped
964A - Splits
1615A - Closing The Gap
4C - Registration System
1321A - Contest for Robots
1451A - Subtract or Divide
1B - Spreadsheet
1177A - Digits Sequence (Easy Edition)
1579A - Casimir's String Solitaire
287B - Pipeline